package huaweiExam;

public class main2 {

    public static void main(String[] args) {
        int target = 11;
        int[] input = {1, 1, 1, 1, 1, 1, 1, 1};
        System.out.println(getMinLength(target, input));

    }

    public static int getMinLength(int target, int[] input) {

        int len = input.length + 1;
        int start = 0;
        int sum = 0;
        for (int i = 0; i < input.length; i++) {
            sum += input[i];
            while (sum >= target) {
                len = Math.min(len, i - start + 1);
                sum -= input[start];
                start++;
            }

        }

        return len > input.length ? 0 : len;
    }
}
